package com.shanxi.cz.module.biz.service.ammetermqtt;

import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;

import java.util.*;
import com.shanxi.cz.module.biz.controller.admin.ammetermqtt.vo.*;
import com.shanxi.cz.module.biz.dal.dataobject.ammetermqtt.AmmeterMqttDO;
import com.shanxi.cz.framework.common.pojo.PageResult;
import com.shanxi.cz.framework.common.util.object.BeanUtils;

import com.shanxi.cz.module.biz.dal.mysql.ammetermqtt.AmmeterMqttMapper;

import static com.shanxi.cz.framework.common.exception.util.ServiceExceptionUtil.exception;
import static com.shanxi.cz.framework.common.util.collection.CollectionUtils.convertList;
import static com.shanxi.cz.module.biz.enums.ErrorCodeConstants.*;

/**
 * mq消息存储 Service 实现类
 *
 * @author 芋道源码
 */
@Service
@Validated
public class AmmeterMqttServiceImpl implements AmmeterMqttService {

    @Resource
    private AmmeterMqttMapper ammeterMqttMapper;

    @Override
    public Integer createAmmeterMqtt(AmmeterMqttSaveReqVO createReqVO) {
        // 插入
        AmmeterMqttDO ammeterMqtt = BeanUtils.toBean(createReqVO, AmmeterMqttDO.class);
        ammeterMqttMapper.insert(ammeterMqtt);

        // 返回
        return ammeterMqtt.getId();
    }

    @Override
    public void updateAmmeterMqtt(AmmeterMqttSaveReqVO updateReqVO) {
        // 校验存在
        validateAmmeterMqttExists(updateReqVO.getId());
        // 更新
        AmmeterMqttDO updateObj = BeanUtils.toBean(updateReqVO, AmmeterMqttDO.class);
        ammeterMqttMapper.updateById(updateObj);
    }

    @Override
    public void deleteAmmeterMqtt(Integer id) {
        // 校验存在
        validateAmmeterMqttExists(id);
        // 删除
        ammeterMqttMapper.deleteById(id);
    }

    @Override
        public void deleteAmmeterMqttListByIds(List<Integer> ids) {
        // 删除
        ammeterMqttMapper.deleteByIds(ids);
        }


    private void validateAmmeterMqttExists(Integer id) {
        if (ammeterMqttMapper.selectById(id) == null) {
            throw exception(AMMETER_MQTT_NOT_EXISTS);
        }
    }

    @Override
    public AmmeterMqttDO getAmmeterMqtt(Integer id) {
        return ammeterMqttMapper.selectById(id);
    }

    @Override
    public PageResult<AmmeterMqttDO> getAmmeterMqttPage(AmmeterMqttPageReqVO pageReqVO) {
        return ammeterMqttMapper.selectPage(pageReqVO);
    }

    @Override
    public List<AmmeterMqttDO> listAmmeterMqtt(AmmeterMqttPageReqVO pageReqVO){
        // AmmeterMqttDO::getAmmeterId,pageReqVO.getAmmeterId(),AmmeterMqttDO::getRecordDate,pageReqVO.getRecordDate()
        return ammeterMqttMapper.selectList(pageReqVO);
    }

}